import Util from 'assets/js/util'
import PCUtil from '../pc-util'
export default {
  data () {
    return {
      searchCondition:{  //查询条件
        cardName:'',
        keyword:'',
        createDate:PCUtil.getPublicTime()
      },
      tableOption:[
        {
          title: '名片昵称',key: 'cardName',align:'left'
        },
        {
          title: '评论内容',key: 'commentContent',align:'left'
        },
        {
          title: '发布时间',key: 'createTime',align:'left'
        },
        {
          title: '处理',key: 'action',align:'left',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px',
                  border:"none",
                  padding: 0,
                  background:"none",
                  color:"#3f94fc",
                  textAlign:'left'
                },
                on: {
                  click: () => {
                    this.toggleShow(params)
                  }
                }
              }, params.row.isPublic==2?'显示':'隐藏')
            ]);
          }
        }

      ],
      commentList:[], //举报处理
      pageSize:10,
      pageNum:1,
      dataTotal:1,
      pageCount:1,
      noticekey:'noticekey1', //Notice弹窗name
      showWarnModal:false, //格式校验提示框
      warnContent:''  //提示文案
    }
  },
  mounted () {
    this.init();
  },
  watch: {
    // 如果路由有变化，会再次执行该方法
    '$route': 'init'
  },
  methods: {
    init: function (newRoute, oldRoute) {
      let routeName = this.$route.name
      if (routeName == "commentList") {
        Util.setTitle('评论管理');
        var param={
          pageNum:1,
          pageSize:this.pageSize,
          startCreateDate:PCUtil.date2TimeStamp(this.searchCondition.createDate[0]),
          endCreateDate:PCUtil.date2TimeStamp(this.searchCondition.createDate[1])
        }
        this.queryCommentList(param)
      }
    },
    /**
     * 查询
     * @param param
     */
    search:function(pageNum){

      this.pageNum=pageNum?pageNum:1;
      var param={
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        cardName:this.searchCondition.cardName,
        keyword:this.searchCondition.keyword,
        startCreateDate:PCUtil.date2TimeStamp(this.searchCondition.createDate[0]),
        endCreateDate:PCUtil.date2TimeStamp(this.searchCondition.createDate[1])

      }
      //console.log(param)
      this.queryCommentList(param);
    },
    /**
     * 查询评论列表接口
     * @param param
     */
    queryCommentList(param){
      let _this=this;
      this.$http.post('convphotoManage/queryComment',param)
        .then(function(resData){
          if (resData.meta.code == 0){
            let data=resData.data;
            console.log(data)
            _this.dataTotal = data.dataTotal||0;
            _this.pageCount = data.pageCount ||0;
            _this.commentList = data.result||[];
          }else{
            _this.showWarnModal = true;
            _this.warnContent = resData.meta.message;
          }

        })
        .catch(function(err){
          // _this.$Modal.warning({
          //   title: '温馨提示',
          //   content: err.meta.message
          // });
          _this.showWarnModal = true;
          _this.warnContent = err.meta.message;
        })
    },
    /**
     * 清空查询条件
     */
    reset(){
      this.searchCondition={  //查询条件
        cardName:'',
        keyword:'',
        createDate:[]
      }
    },
    /**
     * 选择创建时间
     * @param data "2017/06/01 19:32 - 2017/06/05 18:20"
     */
    selectCreateDate(data){

      data=data.split('-')
      if(data.length==2){
        this.searchCondition.createDate[0]=data[0];
        this.searchCondition.createDate[1]=data[1];
      }
      console.log(this.searchCondition.createDate);
    },
    /**
     * 切换显示/隐藏
     * @param params
     */
    toggleShow(params){
      //console.log(params)
      let _this=this;
      let param={
        id:params.row.appraiseId,
        isPublic:params.row.isPublic==2?1:2
      };
      this.$Notice.close(_this.noticekey);
      this.$http.post('convphotoManage/delComment',param)
        .then(function(resData){
          if(resData.meta.code==0){
            //setTimeout(function(){
              _this.search(_this.pageNum)
              _this.$Notice.success({
                title: '温馨提示',
                desc: '操作成功',
                name:_this.noticekey,
                duration:2,
              });
            //},400)
          }else{
            // _this.$Modal.warning({
            //   title: '温馨提示',
            //   content: resData.meta.message
            // });
            _this.showWarnModal = true;
            _this.warnContent = resData.meta.message;
          }
        })
        .catch(function(err){
          // _this.$Modal.warning({
          //   title: '温馨提示',
          //   content: err.meta.message
          // });
          _this.showWarnModal = true;
          _this.warnContent = err.meta.message;
        })
    },
    clearTime(){
      this.searchCondition.createDate=[];
    },
    closeModal(){
      this.showWarnModal = false;
    }
  }
}
